package com.atom.module.lib.opengles.buffer

import android.opengl.GLES30
import com.atom.module.lib.opengles.draw.GlBindable
import com.atom.module.lib.opengles.util.ShaderUtils


open class GlBuffer(public val target: Int, id: Int? = null) : GlBindable {

    val id: Int = id ?: run {
        val array = IntArray(1)
        GLES30.glGenBuffers(1, array, 0)
        ShaderUtils.checkGLError("glGenBuffers")
        array[0]
    }

    override fun bind() {
        GLES30.glBindBuffer(target, id)
    }

    override fun unbind() {
        GLES30.glBindBuffer(target, 0)
    }

    public fun release() {
        GLES30.glDeleteBuffers(1, intArrayOf(id), 0)
    }
}